<!-- head -->
{include file='public/head' /}
<!-- head -->
<script src="__STATIC__/AdminLTE/plugins/treeview/bootstrap-treeview.min.js" type="text/javascript"></script>
<link href="__STATIC__/AdminLTE/plugins/treeview/bootstrap-treeview.min.css" rel="stylesheet" type="text/css" />
<!-- left -->
{include file='public/left' /}
<!-- left -->

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            分配权限
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 权限管理</a></li>
            <li><a href="{:url('/Admin/AdminList','','')}">管理员</a></li>
            <li class="active">权限管理</li>
        </ol>
    </section>

    <div class="pad margin no-print">
        <div class="callout callout-info" style="margin-bottom: 0!important;">
            <h4><i class="fa fa-info"></i> 注意:</h4>
            权限涉及到平台数据的安全，勾选以后该用户就会获取相应的权限，请管理员慎重操作.
        </div>
    </div>

    <!-- Main content -->
    <section class="invoice">
        <!-- title row -->
        <div class="row">
            <div class="col-xs-12">
                <h2 class="page-header">
                    <i class="glyphicon glyphicon-globe"></i> 功能模块
                </h2>
            </div>
            <!-- /.col -->
        </div>
        <form class="form-horizontal" method="post" action="{:url('Admin/role','','')}" enctype="multipart/form-data">
            <input type="hidden" name="id" value="{$id}">
            <input type='hidden' name='role' id="role" value="{$role}">
            <!-- info row -->
            <div id="tree"></div>
            <input type="hidden" id="returndata" value='{$returndata}'>
            <div class="box-footer">
                <button type="button" onclick="zhankai()">展开</button>
                <button type="button" onclick="zhedie()">折叠</button>
                <button type="button" onclick="quanxuan()">全选</button>
                <button type="submit" class="btn btn-info pull-right" name="submit" value="3">保存修改</button>
            </div>
        </form>
    </section>
    <!-- /.content -->
    <div class="clearfix"></div>
</div>
<script type="text/javascript">
    var role = "{$role}";
    var rolearray = role.split(","); //字符分割
    for (var i = 0; i < rolearray.length; i++) {
        $("input:checkbox[value='" + rolearray[i] + "']").attr('checked', 'true');
    }
</script>
<script>
    var returndata = $('#returndata').val();

    $('#tree').treeview({
        data: returndata,
        showCheckbox: true,
        showTags: true,
        multiSelect: true,
        onNodeChecked: function (event, data) {
            var all = $('#tree').treeview('getChecked');
            var role='';
            for(var i=0;i<all.length;i++){
                var dd = all[i]['tags'][0];
                role=role+dd+',';
            }
            role=role.substr(0,role.length-1);
            $('#role').val(role);

        },
        onNodeUnchecked: function (event, data) {
            var all = $('#tree').treeview('getChecked');
            var role='';
            for(var i=0;i<all.length;i++){
                var dd = all[i]['tags'][0];
                role=role+dd+',';
            }
            role=role.substr(0,role.length-1);
            $('#role').val(role);
        },
       
    });
    /*初始化折叠*/
    $(function () {
        $('#tree').treeview('collapseAll', {silent: true});
    });
    /*全部展开*/
    function zhankai(){
        $('#tree').treeview('expandAll', { levels: 2, silent: true });
    };
    /*全部折叠*/
    function zhedie(){
        $('#tree').treeview('collapseAll', { silent: true });
    };
    /*全选*/
    function quanxuan(){
        $('#tree').treeview('checkAll', {silent: true});
        var all = $('#tree').treeview('getChecked');
            var role='';
            for(var i=0;i<all.length;i++){
                var dd = all[i]['tags'][0];
                role=role+dd+',';
            }
            role=role.substr(0,role.length-1);
            $('#role').val(role);
    };
</script>
<!-- foot -->
{include file='public/foot' /}
<!-- foot -->